package com.qimou.iems.service.impl;

import com.qimou.iems.entity.Company;
import com.qimou.iems.entity.PageArgs;
import com.qimou.iems.entity.PageList;
import com.qimou.iems.mapper.ICompanyMapper;
import com.qimou.iems.service.ICompanyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Qimou Xie
 * @date 2018/3/14 22:06.
 **/

@Service
public class CompanyServiceImpl implements ICompanyService {

    @Resource
    private ICompanyMapper companyMapper;

    @Override
    public List<Company> getCompany(Map<String, Object> map) {
        return companyMapper.selectCompany(map);
    }

    @Override
    public Company getCompany(Integer companyId) {
        return companyMapper.selectById(companyId);
    }

    @Override
    public PageList<Company> getCompany(PageArgs pageArgs, Map<String, Object> map) {
        PageList<Company> companyPageList = new PageList<Company>();
        int count = companyMapper.countCompany(map);
        if(count > 0){
            map.put("pageArgs",pageArgs);
            companyPageList.setList(companyMapper.selectCompany(map));
        }
        companyPageList.setTotalSize(count);
        return companyPageList;
    }

    @Override
    public void save(Company company) {
        companyMapper.insert(company);
    }

    @Override
    public void update(Company company) {
        companyMapper.updateById(company);
    }

    @Override
    public List<Company> getAllCompany() {
        return companyMapper.selectAllCompany();
    }
}
